﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Payroll.BusinessLogic;
using Payroll.Common.Utils;
using Payroll.Common.Utils.Html;
using PayrollHR.Web;
using Payroll.BusinessLogic.CustomerManager;
using Payroll.BusinessLogic.Directory;
using Payroll.BusinessLogic.Utils;
using Payroll.BusinessLogic.ExportImport;
using Payroll.BusinessLogic.Company;
using Payroll.BusinessLogic.MyCompany;

namespace PayrollHR.Administration.Modules
{
    public partial class MyCompanyControl : BasePayrollAdministrationUserControl
    {
        private const int m_pageSize = 50;
        public int MyCompanyID
        {
            get
            {
                return CommonHelper.QueryStringInt("MyCompanyID");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                Bind();
            }
        }
        protected void Bind()
        {
            var company = this.CompanyServices.GetCompany();
            if (!CommonHelper.IsNull(company))
            {
                txtComName.Text = company.Name;
                txtAdress.Text = company.Address;
                txtTaxcode.Text = company.TaxCode;
                txtEmailSend.Text = company.EmailSend;
                txtReceive.Text = company.Receive;
                txtPassword.Text = company.EmailPassword;
                txtHost.Text = company.Host;
                txtPort.Text = CommonHelper.ToString(company.Port);
                txtMailTo.Text = company.EmailSender;
            }
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            this.Save();
        }
        #region Save
        protected void Save()
        {
            Company item = new Company
            {
                MyCompanyID = this.MyCompanyID,
                Name = txtComName.Text.Trim(),
                Address = txtAdress.Text.Trim(),
                TaxCode = txtTaxcode.Text.Trim(),
                EmailSend = txtEmailSend.Text.Trim(),
                Receive = txtReceive.Text.Trim(),
                IsActive = true,
                Createby = PayrollContext.Current.Session.EmployeeId,
                Modified = PayrollContext.Current.Session.EmployeeId,
                ModifiedDate = DateTime.Now,
                Host = txtHost.Text.Trim(),
                Port = int.Parse(txtPort.Text),
                EmailPassword = txtPassword.Text.Trim(), 
                EmailSender = txtMailTo.Text.Trim()
            };
            this.CompanyServices.Save(item);
        }
        #endregion
    }
}